package com.example.drugs1.controllers;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;


@Controller
public class HomeControllers {
    @RequestMapping("/")
    public String displayHome(Model model){
        Authentication authentication= SecurityContextHolder.getContext().getAuthentication();
        if ("anonymousUser".equals(authentication.getName())){
            model.addAttribute("name","未登录");
        }else {
            model.addAttribute("name",authentication.getName());
        }
        return "main/home";
    }
}
